/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pkg4funparse;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import pkg4funlex.Analyzer;
import pkg4funlex.Reserved;
import pkg4funlex.Scanner;
import pkg4funlex.Token;

/**
 *
 * @author l
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader inFile = null;
        Token token;
        //String sourceFilePath = args[0];

          String sourceFilePath = "testeRecursivo.4f";
//        String sourceFilePath = "testePreditivo.4f";

          String which = "recursive";
//        String which = "predictive";

        System.out.println(System.getProperty("user.dir") + " " + sourceFilePath);
        try {
            Reserved.init("reservadas.txt");
        } catch (Exception ex) {
            System.out.println("Não deu pra inicializar mapeamento das reservados: "+ex.getLocalizedMessage());
            System.exit(1);
        }

        try {
            inFile = new BufferedReader(new FileReader(sourceFilePath));
            Scanner.init(inFile);
            Analyzer.init();
            if(which.equals("recursive")) {
                Input.init("saidaRec");
                RecursiveAnalyser.init();
            }
            else if(which.equals("predictive")) {
                Input.init("saida");
                PredictiveAnalyzer.init();
            } else {
                System.out.println("Modo de usar: javc - jar analizer.jar fonte.4f predictive|recursive");
                System.exit(0);
            }

            // TODO code application logic here
        } catch (FileNotFoundException ex) {
            System.out.println("NÃO CONSEGUI ABRIR UM ARQUIVO! " + ex.getLocalizedMessage());
        } finally {
            try {
                inFile.close();
            } catch (IOException ex) {
                System.out.println("Erro" + ex.getLocalizedMessage());
            }
        }
    }
}
